﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Modules.CashBook.Data;

namespace DotNetNuke.Modules.CashBook.Components

{
    ///<summary>
    ///This class provides the tie between
    ///the dnn CBO providers and the modules data
    ///</summary>
   
    public class CashLineController
    {
        public static CashLine GetCashLine(int LineId)
        {
           return CBO.FillObject<CashLine>(DataProvider.Instance().GetCashLine(LineId));
        }

        public static List<CashLine> GetCashBook(int ModuleId)
        {
            return CBO.FillCollection<CashLine>(DataProvider.Instance().GetCashBook(ModuleId));
        }

        public static Total TotalCashBook(int ModuleId)
        {
            return CBO.FillObject<Total>(DataProvider.Instance().TotalCashBook(ModuleId));
        }

        public static void DeleteCashLine(int LineId)
        {
            DataProvider.Instance().DeleteCashLine(LineId);
        }

        public static int SaveCashLine(CashLine t, int tabId)
        {
            if (t.LineId < 1)
            {
                t.LineId = DataProvider.Instance().AddCashLine(t);

                //add content item integration
                var cntTaxonomy = new Taxonomy.Content();
                var objContentItem = cntTaxonomy.CreateContentItem(t, tabId);
                t.ContentItemId = objContentItem.ContentItemId;
                SaveCashLine(t, tabId);
            }
            else
            {
                DataProvider.Instance().UpdateCashLine(t);
                var cntTaxonomy = new Taxonomy.Content();
                cntTaxonomy.UpdateContentItem(t, tabId);
            }
            return t.LineId;
        }
    }
}